package club.janna.jrpc.remoting.netty;

import club.janna.jrpc.util.ByteUtil;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

public class FrameEncoder extends MessageToByteEncoder<byte[]> {

    @Override
    protected void encode(ChannelHandlerContext ctx, byte[] msg, ByteBuf out) throws Exception {
        out.writeByte(0xCA);
        out.writeByte(0xFE);
        out.writeBytes(ByteUtil.int2byte(msg.length));
        out.writeBytes(msg);
    }
}
